<template>
  <div class="VipReg">
    <div class="VipReg-content wrap">
      <div class="auditText" v-show="isUpdate">
        <div class="auditTitle">审核结果</div>
        <div>
          <div class="auditItem" v-for="(item,index) in declareAudit" :key="index">
            <div class="auditInfo">{{item.result}}：{{item.text}}</div>
            <div class="auditTime">{{item.createTime}}</div>
          </div>
        </div>
      </div>
      <div class="VipReg-content-form">
        <van-form @submit="onSubmit" label-align="right">
          <van-field
            v-model="form.companyName"
            label="单位名称"
            placeholder="请输入单位名称"
            :rules="[{ required: true, message: '单位名称不能为空' }]"
          />

          <van-field
            v-model="form.sex"
            label="主管单位"
            placeholder="请输入主管单位"
            :rules="[{ required: true, message: '主管单位不能为空' }]"
          />

          <van-field
            v-model="form.companyAddress"
            label="通讯地址"
            placeholder="请输入通讯地址"
            :rules="[{ required: true, message: '通讯地址不能为空' }]"
          />

          <van-field v-model="form.postcode" label="邮编" placeholder="没有填写无" />

          <van-field
            readonly
            clickable
            :value="form.birthday"
            label="成立时间"
            placeholder="点击选择成立时间"
            :rules="[{ required: true, message: '成立时间不能为空' }]"
            @click="showCalendar = true"
          />
          <van-popup v-model="showCalendar" position="bottom">
            <van-datetime-picker
              v-model="birthDate"
              type="date"
              title="成立时间"
              :min-date="minDate"
              :max-date="maxDate"
              @cancel="showCalendar=false"
              @confirm="onConfirm"
            />
          </van-popup>
          <van-field
            v-model="form.workYear"
            label="职工人数"
            placeholder="请输入职工人数"
            :rules="[{ required: true, message: '职工人数不能为空' }]"
          />

          <van-field
            v-model="form.politicalStatus"
            label="经济性质"
            placeholder="请输入经济性质"
            :rules="[{ required: true, message: '经济性质不能为空' }]"
          />

          <van-field
            v-model="form.educationalLevel"
            label="注册资金"
            placeholder="请输入注册资金"
            :rules="[{ required: true, message: '注册资金不能为空' }]"
          />

          <van-field
            v-model="form.jobTitle"
            label="单位网址"
            placeholder="请输入单位网址"
            :rules="[{ required: true, message: '单位网址不能为空' }]"
          />

          <van-field
            v-model="form.emailQq"
            label="单位邮箱"
            placeholder="请输入单位邮箱"
            :rules="[{ required: true, message: '单位邮箱不能为空' }]"
          />

          <van-field
            v-model="form.position"
            label="法人代表"
            placeholder="请输入法人代表"
            :rules="[{ required: true, message: '法人代表不能为空' }]"
          />

          <van-field
            v-model="form.contactPhone"
            label="单位职务"
            placeholder="请输入单位职务"
            :rules="[{ required: true, message: '单位职务不能为空' }]"
          />

          <van-field v-model="form.address" label="座 机" placeholder="请输入座机" />

          <van-field
            v-model="form.principalPhone"
            label="手 机"
            placeholder="请输入手机"
            :rules="[{ required: true, message: '手机不能为空' }]"
          />

          <van-field
            v-model="form.picture"
            label="联系人"
            placeholder="请输入联系人"
            :rules="[{ required: true, message: '联系人不能为空' }]"
          />

          <van-field
            v-model="form.professionalCategory"
            label="单位职务"
            placeholder="请输入单位职务"
            :rules="[{ required: true, message: '单位职务不能为空' }]"
          />

          <van-field v-model="form.productionName" label="座 机" placeholder="请输入座机" />

          <van-field
            v-model="form.productionCategory"
            label="手 机"
            placeholder="请输入手机"
            :rules="[{ required: true, message: '手机不能为空' }]"
          />

          <van-field v-model="form.faxes" label="传 真" placeholder="没有填写无" />

          <van-field
            v-model="form.weChat"
            label="QQ号"
            placeholder="请输入QQ号"
            :rules="[{ required: true, message: 'QQ号不能为空' }]"
          />

          <van-field
            v-model="form.speciality"
            label="从事领域"
            placeholder="请输入从事领域"
            :rules="[{ required: true, message: '从事领域不能为空' }]"
          />

          <van-field
            v-model="form.jobResume"
            type="textarea"
            label="主营业务"
            placeholder="请输入主营业务"
            :rules="[{ required: true, message: '主营业务不能为空' }]"
          />

          <van-field
            v-model="form.workPerformance"
            type="textarea"
            label="公司简介及资质情况"
            placeholder="请输入公司简介及资质情况"
          />
          <!-- <div class="VipReg-content-file">
            <span>附件下载</span>
            <a href="javascript:;">JGJ56251HGF6.PDF</a>
          </div>-->
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">提交审核</van-button>
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>

<script>
import { parseTime } from "@/utils";
export default {
  name: "kejiweihuiyuan",
  props: {
    vipTypeId: {
      type: Number,
      default: 0
    },
    tableName: {
      type: String,
      default: ""
    },
    isUpdate: {
      type: Boolean,
      default: false
    },
    declareId: {
      type: Number,
      default: 0
    }
  },
  mounted() {
    if (this.isUpdate) {
      this.findDeclareAudit();
      this.findDeclare();
    }
  },
  methods: {
    // 表单提交方法
    onSubmit() {
      console.log(this.form);
      if(this.isUpdate){
        this.updateDeclare();
      }else{
        this.addDeclare();
      }
      
    },
    updateDeclare(){
      let param = JSON.parse(JSON.stringify(this.form));
      param.declareType = 2;
      param.status = 0;
      this.$request({
        url: "/award/updateAwardDeclare",
        method: "post",
        data: param
      }).then(rsp => {
        if (rsp.code === 200) {
          this.$router.replace({ path: "/vipAudit" });
        } else {
          this.$toast.fail(rsp.content);
        }
      });
    },  
    addDeclare(){
      let param = JSON.parse(JSON.stringify(this.form));
      param.declareName = this.tableName;
      param.declareType = 2;
      param.vipTypeId = this.vipTypeId;
      param.status = 0;
      param.signature2 = this.tableName;
      this.$request({
        url: "/award/addAwardDeclare",
        method: "post",
        data: param
      }).then(rsp => {
        if (rsp.code === 200) {
          this.$router.replace({ path: "/vipAudit" });
        } else {
          this.$toast.fail(rsp.content);
        }
      });
    },
    // 日历选择
    onConfirm() {
      this.form.birthday = `${this.birthDate.getFullYear()}-${this.birthDate.getMonth() +
        1}-${this.birthDate.getDate()}`;
      this.showCalendar = false;
    },
    // 政治面貌选择
    confirmPublicFace(value) {
      this.publicFace = value;
      this.showPublicFace = false;
    },
    // 学历选择
    confirmEdu(value) {
      this.edu = value;
      this.showEdu = false;
    },
    findDeclareAudit() {
      this.$request({
        url: "/award/awardApprovalList",
        method: "post",
        data: { declareId: this.declareId }
      }).then(rsp => {
        if (rsp.code === 200) {
          this.declareAudit = rsp.data;
        } else {
          this.$toast.fail(rsp.content);
        }
      });
    },
    findDeclare() {
      this.$request({
        url: "/award/selectOneAwardDeclare",
        method: "post",
        data: { declareId: this.declareId }
      }).then(rsp => {
        if (rsp.code === 200) {
          // rsp.data.signature1 = JSON.parse(rsp.data.signature1);
          // rsp.data.signature2 = JSON.parse(rsp.data.signature2);
          this.form = rsp.data;
          // this.tableName = this.form.declareName;
          // this.vipTypeId = this.form.vipTypeId;
        } else {
          this.$toast.fail(rsp.content);
        }
      });
    }
  },
  data() {
    return {
      declareAudit: [],
      form: {
        birthday: parseTime(new Date(), "{y}-{m}-{d}")
      },
      username: "",
      sex: "1",
      showCalendar: false,
      birthDate: parseTime(new Date(), "{y}-{m}-{d}"),
      date: "",
      minDate: new Date(1950, 0, 1),
      maxDate: new Date(),
      place: "", // 籍贯
      publicFace: "", // 政治面貌
      faceColumns: ["群众", "共青团员", "党员"],
      showPublicFace: false,
      edu: "", // 学历
      eduColumns: ["小学", "初中", "高中", "大专", "本科", "硕士"],
      showEdu: false,
      profession: "", // 职称
      photo: [{ url: "" }],
      workYears: "",
      school: "",
      study: "",
      cardID: "",
      email: "",
      companyName: "", // 单位名称
      companyWork: "",
      tel: "",
      fox: "",
      phone: "",
      location: "",
      abbreviation: "", // 邮编
      workCategory: "1",
      experience: "", // 工作简历
      workMark: "", // 工作业绩
      flag: false
    };
  }
};
</script>

<style lang='scss'>
@import "@/assets/css/base";

.VipReg {
  &-banner {
    // @include bgImg(100%, px2rem(186), '@/assets/img/vip/vip-reg-banner.png');
    text-align: center;
    & > p {
      color: #fffefe;
      font-size: px2rem(24);
      font-weight: bold;
      &.title {
        font-size: px2rem(30);
        font-weight: bold;
        margin-top: px2rem(60);
        margin-bottom: px2rem(22);
      }
    }
  }
  &-content {
    .auditText {
      display: flex;
      margin-top: px2rem(40);
      .auditTitle {
        font-size: px2rem(32);
        width: 26%;
        text-align: right;
        padding-right: px2rem(32);
      }
      .auditItem {
        margin-bottom: px2rem(20);
        .auditInfo {
          color: #000000;
          margin-bottom: px2rem(20);
          font-size: px2rem(32);
        }
        .auditTime {
          font-size: px2rem(28);
          color: #dcdee0
        }
      }
    }
    &-info {
      margin-top: px2rem(83);
      margin-bottom: px2rem(40);
      & > p {
        color: #565656;
        font-size: px2rem(24);
        margin-bottom: px2rem(30);
        line-height: px2rem(38);
      }
    }
    &-file {
      font-size: px2rem(28);
      margin-top: px2rem(30);
      box-sizing: border-box;
      padding-left: px2rem(70);
      & > a {
        padding-left: px2rem(47);
        color: $mainColor;
        font-size: px2rem(28);
      }
    }
  }
}
</style>
